(*
   Copyright (c) 2023-2025 Semgrep Inc.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public License
   version 2.1 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file
   LICENSE for more details.
*)
val run_subprocess :
  Cap.Exec.t ->
  ?env:Cmd.env ->
  Cmd.t ->
  (Bos.OS.Cmd.status, [> Rresult.R.msg ]) result
(** Like status_of_run but does not capture stdout or stderr of the process
    running. Useful to replicate CLI behavior similar to execv* commands, which
    don't work on Windows. *)

(*
   The following functions capture the error output of the command being run
   and logs it as the info level, allowing it to be silenced by adjusting
   the log level.
*)
val string_of_run :
  Cap.Exec.t ->
  trim:bool ->
  ?env:Cmd.env ->
  Cmd.t ->
  (string * Cmd.run_status, [ `Msg of string ]) result

val string_of_run_with_stderr :
  Cap.Exec.t ->
  trim:bool ->
  ?env:Cmd.env ->
  Cmd.t ->
  (string * Cmd.run_status, [ `Msg of string ]) result * string
(** Like string_of_run but instead of logging the stderr output, it captures it and returns it (in both success and failure cases). *
 * The first part of the return type matches the return value of `string_of_run`; the last string part contains the stderr contents *)

val lines_of_run :
  Cap.Exec.t ->
  trim:bool ->
  ?env:Cmd.env ->
  Cmd.t ->
  (string list * Cmd.run_status, [ `Msg of string ]) result

val status_of_run :
  Cap.Exec.t ->
  ?quiet:bool ->
  ?env:Cmd.env ->
  Cmd.t ->
  (Bos.OS.Cmd.status, [ `Msg of string ]) result

(* Deprecated: you should use lines_of_run *)
val cmd_to_list : Cap.Exec.t -> ?verbose:bool -> string (* cmd *) -> string list

(* Deprecated: you should probably use one of the xxx_of_run above *)
val with_open_process_in :
  Cap.Exec.t -> string (* cmd *) -> (in_channel -> 'a) -> 'a
